package com.stylefeng.guns.modular.pay.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.log.LogObjectHolder;
import com.stylefeng.guns.modular.pay.model.WechatApp;
import com.stylefeng.guns.modular.pay.service.IWechatAppService;

/**
 * 微信配置控制器
 *
 * @author fengshuonan
 * @Date 2018-09-07 13:47:20
 */
@Controller
@RequestMapping("/wechatApp")
public class WechatAppController extends BaseController {

    private String PREFIX = "/pay/wechatApp/";

    @Autowired
    private IWechatAppService wechatAppService;

    /**
     * 跳转到微信配置首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "wechatApp.html";
    }

    /**
     * 跳转到添加微信配置
     */
    @RequestMapping("/wechatApp_add")
    public String wechatAppAdd() {
        return PREFIX + "wechatApp_add.html";
    }

    /**
     * 跳转到修改微信配置
     */
    @RequestMapping("/wechatApp_update/{wechatAppId}")
    public String wechatAppUpdate(@PathVariable Integer wechatAppId, Model model) {
        WechatApp wechatApp = wechatAppService.selectById(wechatAppId);
        model.addAttribute("item",wechatApp);
        LogObjectHolder.me().set(wechatApp);
        return PREFIX + "wechatApp_edit.html";
    }

    /**
     * 获取微信配置列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return wechatAppService.selectList(null);
    }

    /**
     * 新增微信配置
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(WechatApp wechatApp) {
        wechatAppService.insert(wechatApp);
        return SUCCESS_TIP;
    }

    /**
     * 删除微信配置
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer wechatAppId) {
        wechatAppService.deleteById(wechatAppId);
        return SUCCESS_TIP;
    }

    /**
     * 修改微信配置
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(WechatApp wechatApp) {
        wechatAppService.updateById(wechatApp);
        return SUCCESS_TIP;
    }

    /**
     * 微信配置详情
     */
    @RequestMapping(value = "/detail/{wechatAppId}")
    @ResponseBody
    public Object detail(@PathVariable("wechatAppId") Integer wechatAppId) {
        return wechatAppService.selectById(wechatAppId);
    }
}
